package com.mmall.controller.portal;

import com.github.pagehelper.PageInfo;
import com.mmall.common.Const;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.Product;
import com.mmall.pojo.User;
import com.mmall.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Create by lisy on Qingdao
 **/
@Controller
@RequestMapping(value = "/product")
public class ProductController {

    @Autowired
    IProductService iProductService;
    /**
     * ####1.产品搜索及动态排序List
     * /product/list.do
     * http://localhost:8080/product/list.do?keyword=&categoryId=1&orderBy=price_desc
     */
    @RequestMapping(value="list.do")
    @ResponseBody
    public ServerResponse<PageInfo> listProduct(@RequestParam(value="keyWord", required = false) String keyWord,
                                                @RequestParam(value="categoryId", required = false) Integer CategoryId,
                                                @RequestParam(value="pageNum", defaultValue = "1") int pageNum,
                                                @RequestParam(value="pageSize", defaultValue = "10") int pageSize,
                                                @RequestParam(value = "orderBy", defaultValue = "") String orderBy){
        return iProductService.getProductByKeyWordCategoryId(keyWord, CategoryId, pageNum, pageSize, orderBy);
    }

    /**
     * ####2.产品detail
     * /product/detail.do
     * http://localhost:8080/product/detail.do?productId=2
     */
    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse detailProduct(Integer productId){
        return iProductService.getProductDetailCustomer(productId);
    }
}
